home *** CD-ROM | disk | FTP | other *** search
/ Palm Utilities / Palm_Utilities_CD-ROM_2001_2001.iso / files / handwriting / Handy Pilot Font Editor 1.7R / FEDEMO.ZIP / EXAMPLE / fexampl.c next >
Encoding:
C/C++ Source or Header  |  2000-06-07  |  4.3 KB  |  199 lines

  1. /*
  2.   fexampl.c:  example of how to use custom font on PalmOS v3.0 or higher.
  3.   (c) 1999 Alexander Ovcharenko
  4. */
  5.  
  6. #pragma pack(2)
  7.  
  8. #include <Common.h>
  9. #include <System/SysAll.h>
  10. #include <System/SysEvtMgr.h>
  11. #include <UI/UIAll.h>
  12. #include "fexampl.h"
  13.  
  14. static    int StartApplication( void );
  15. static    int StopApplication( void );
  16. static    Word EventLoop( void );
  17. static    Boolean AboutHandler( EventPtr );
  18. static    Boolean FExamplHandler( EventPtr );
  19.  
  20. static  VoidHand    FontHandle0, FontHandle1, FontHandle2, FontHandle3;
  21.  
  22. DWord PilotMain (Word cmd, Ptr cmdPBP, Word launchFlags)
  23. {
  24.   int error;
  25.   ULong version;
  26.  
  27. if (cmd == sysAppLaunchCmdNormalLaunch)
  28.  {
  29.  
  30.    version=0;
  31.    FtrGet(sysFtrCreator,sysFtrNumROMVersion,&version);
  32.  
  33.    if(version<0x03000000l)
  34.  FrmAlert(AlertID_LowVersion);
  35.     else
  36.     {
  37.      error = StartApplication();    // Application start code
  38. .
  39.      if (error) return error;
  40.      EventLoop();            // Event loop
  41. .
  42.      StopApplication();            // Application stop code
  43. .
  44.     }
  45.  }
  46.   return 0;
  47. }
  48.  
  49.  
  50. static int StartApplication( void )
  51.  { 
  52.     /* 'pFNT' and 0x03e8 are font resourse name and font ID value. */
  53.  
  54.     FontHandle0=DmGetResource('pFNT',0x03e8);
  55.     FontHandle1=DmGetResource('pFNT',0x03e9);
  56.     FontHandle2=DmGetResource('pFNT',0x03ea);
  57.  
  58.     /* Now we define ID for memory block of custom font. 
  59.     Font ID should be greater than 128 because value less than 128 are 
  60.     reserved for system use. */
  61.  
  62.     if (FontHandle0!=NULL) FntDefineFont(Font_Nufont,MemHandleLock(FontHandle0));
  63.     if (FontHandle1!=NULL) FntDefineFont(Font_Times,MemHandleLock(FontHandle1));
  64.     if (FontHandle2!=NULL) FntDefineFont(Font_Narrowed,MemHandleLock(FontHandle2));
  65.  
  66.     FrmGotoForm(FormID_FExample);
  67.     return 0;
  68.   }
  69.  
  70. static int StopApplication(void)
  71. {
  72.     FrmCloseAllForms();
  73.  
  74.     /* Unlock and release custom font resources */
  75.  
  76.     MemHandleUnlock( FontHandle0 );
  77.     MemHandleUnlock( FontHandle1 );
  78.     MemHandleUnlock( FontHandle2 );
  79.  
  80.     DmReleaseResource( FontHandle0 );
  81.     DmReleaseResource( FontHandle1 );
  82.     DmReleaseResource( FontHandle2 );
  83.     return 0;
  84. };
  85.  
  86. static Word EventLoop( void )
  87.   EventType event;
  88.   FormPtr CurrentForm;
  89.   Word FormID;
  90.   Word error;
  91.  
  92. do
  93.   {
  94.     EvtGetEvent(&event,600);
  95.  
  96.     if (SysHandleEvent(&event)) continue;
  97.     if (MenuHandleEvent((void *)0, &event, &error)) continue;
  98.     
  99.     if (event.eType == frmLoadEvent)
  100.        { 
  101.     FormID=event.data.frmLoad.formID;
  102.     CurrentForm=FrmInitForm(FormID);
  103.     FrmSetActiveForm(CurrentForm);
  104.         
  105.     switch (FormID)
  106.        { 
  107.         case FormID_FExample:
  108.             FrmSetEventHandler(CurrentForm,FExamplHandler);
  109.             break;
  110.  
  111.         case FormID_About:
  112.             FrmSetEventHandler(CurrentForm,AboutHandler);
  113.         break;
  114.        };
  115.     };
  116.       FrmDispatchEvent(&event);
  117.     } while (event.eType != appStopEvent);
  118.  
  119.   return 0;
  120. }
  121.  
  122. static Boolean FExamplHandler( EventPtr event)
  123. {
  124.   Boolean  Handled=false;
  125.   FormPtr  CurrentForm;
  126.   CurrentForm=FrmGetActiveForm();    
  127.   Handled=false;
  128.   
  129.   switch (event->eType)
  130.          {
  131.       case frmOpenEvent:    /* Draw all objects of the active form. */
  132.              FrmDrawForm(CurrentForm);
  133.          Handled=true;
  134.         break;
  135.  
  136.       case menuEvent:
  137.           Handled=true;
  138.          switch ( event->data.menu.itemID)
  139.          {
  140.             case MenuID_About:
  141.              FrmPopupForm(FormID_About);
  142.             break;
  143.  
  144.             default:
  145.              Handled=false;
  146.             break;
  147.          };
  148.         break;
  149.  
  150.      case ctlSelectEvent:
  151.             switch ( event->data.ctlEnter.controlID ) 
  152.         {
  153.         };
  154.          break;
  155.  
  156.         case frmCloseEvent:
  157.              FrmEraseForm(FrmGetActiveForm());
  158.              FrmDeleteForm(FrmGetActiveForm());
  159.              Handled=true;
  160.              break;
  161.  
  162.                   default:
  163.           Handled=false;
  164.     break;
  165.       }
  166.     return (Handled);
  167. }
  168.  
  169. static Boolean AboutHandler( EventPtr event)
  170. {     Boolean Handled=false;
  171.  
  172.       Handled=false;
  173.       switch (event->eType) 
  174.              {    case frmOpenEvent:           /* Draw all objects of the active form. */
  175.                  FrmDrawForm(FrmGetActiveForm());
  176.              Handled=true;
  177.             break;
  178.  
  179.         case ctlSelectEvent:
  180.             switch ( event->data.ctlEnter.controlID) 
  181.              {
  182.               case ButtonID_AboutOk:
  183.                   FrmReturnToForm(FormID_FExample);
  184.                       Handled=true;
  185.                   break;
  186.              };
  187.         break;
  188.         
  189.         case frmCloseEvent:
  190.              FrmEraseForm(FrmGetActiveForm());
  191.              FrmDeleteForm(FrmGetActiveForm());
  192.              Handled=true;
  193.             break;
  194.  
  195.         default:
  196.          Handled=false;
  197.         break;     
  198.            };
  199.  
  200.     return (Handled);          
  201. };
  202.